﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIScript : MonoBehaviour {
    public Text txtTimer;
    public InputField inpH;
    public InputField inpV;
    public InputField inpMiss;
    public GameObject goInitGame;
    public Button btnSetting;
    public Button btnStartGame;

    public InitMaze initMaze;
    public GetBall getBall;

    [SerializeField]
    private float totalTime = 0;


	// Use this for initialization
	void Start ()
    {
        txtTimer.text = "00:00:00";

        btnStartGame.onClick.AddListener(delegate () { StartGame(); });
        btnSetting.onClick.AddListener(delegate() { GameSetting(); });
    }



    // Update is called once per frame
    void Update ()
    {
        totalTime += Time.deltaTime;
        TimeShow();
    }
    void TimeShow()
    {
        int i1 = 0, i2 = 0, i3 = 0;
        i1 = (int)totalTime;
        while (i1 >=59)
        {
            i2++;
            while (i2>=59)
            {
                i3++;
                i2 -= 59;
            }
            i1 -= 59;
        }
        string str1, str2, str3;
        str1 = i1 > 9 ? i1.ToString() : ("0" + i1.ToString());
        str2 = i2 > 9 ? i2.ToString() : ("0" + i2.ToString());
        str3 = i3 > 9 ? i3.ToString() : ("0" + i3.ToString());

        txtTimer.text = str3 + ":"+str2 + ":" + str1;
    }
    void StartGame()
    {
        int hInpt =int.Parse( inpH.text);
        int vInput = int.Parse(inpV.text);
        int missInput = int.Parse(inpMiss.text);
        hInpt = hInpt < 10 ? 10 : hInpt;
        hInpt = hInpt > 100 ? 100 : hInpt;
        vInput = vInput < 10 ? 10 : vInput;
        vInput = vInput > 100 ? 100 : vInput;
        missInput = missInput > 6 ? 6 : missInput;
        missInput = missInput < 3 ? 3 : missInput;

        goInitGame.SetActive(false);

        initMaze.iMiss = missInput;
        initMaze.BuildHome(hInpt, vInput);
        getBall.InitBall();

    }

    private void GameSetting()
    {
       
    }
}
